package ui;

import services.FurnitureServicempl;
import vo.Furniture;

import java.util.List;
import java.util.Scanner;

public class FurnitureLogin {
  static   FurnitureServicempl furnitureServicempl=new FurnitureServicempl();  //对家具表进行操作的类对象,
   static Scanner scanner=new Scanner(System.in);
    public static void Login(){ //家具表页面
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择:--->");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){  //返回值为TRUE
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
                break;
            case 2:
                if (delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
                break;
            case 3:
                if (modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
                break;
            case 4:
                Furniture furniture=getcustombyid();
                System.out.println(furniture);
                break;
            case 5:
                List<Furniture> list=getall();
                for(Furniture furniture1:list){
                    System.out.println(furniture1);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }
    private static boolean add(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入家具编号:");
        int id=scanner.nextInt();
        System.out.println("请输入家具种类:");
        String type=scanner.nextLine();
        System.out.println("请输入家具价格:");
        int price=scanner.nextInt();
        System.out.println("请输入家具剩余数量:");
        int count=scanner.nextInt();
        Furniture furniture=new Furniture(id,type,price,count);
        return furnitureServicempl.add(furniture);
    }
    private static boolean delet(){  //通过id删除信息
        System.out.println("请输入你要删除的家具编号--id");
        int id=scanner.nextInt();
        Furniture furniture=new Furniture(id);
       return furnitureServicempl.delete(furniture);
    }
    private static boolean modify(){  //传入新的家具信息
        System.out.println("请输入新的家具编号:");
        int id=scanner.nextInt();
        System.out.println("请输入新的家具种类:");
        String type=scanner.nextLine();
        System.out.println("请输入新的家具价格:");
        int price=scanner.nextInt();
        System.out.println("请输入新的家具剩余数量");
        int count=scanner.nextInt();
        Furniture furniture=new Furniture(id,type,price,count);
        return furnitureServicempl.delete(furniture);
    }
    private static Furniture getcustombyid(){ // 通过id进行查询信息
        System.out.println("请输入你要查询的家具的id");
        String id=scanner.nextLine();
        return furnitureServicempl.getcustombyid(id);
    }
    private static List<Furniture> getall(){ //查询所有的信息
        return furnitureServicempl.getall();
    }

}
